<?php

class Core_Model_Permission_Collection_Accredit_Action extends Dcmp_Model_Collection_Strong {

    public function __construct(){
        parent::__construct();
        $this->setItemClass('permission/accredit_action');
        $this->from('{t}permission_accredit_action', 'a')->field('a.*');
    }

    public function joinArea(){
        $this->join()
                ->inner('{t}global_area', 'b')->on('a.area_id', 'b.id')
             ->closest()
             ->select()
                ->field('b.name', 'area_name');
        return $this;
    }

    public function filterBy($name, $arg) {
        switch($name){
            case 'area':
                return $this->eq('area_id', ':areaId:s')->addParameter('areaId', $arg);
        }
        return parent::filterBy($name, $arg);
    }
}